package day_2022_1_to_2.leetcode;

import java.util.Stack;

//232. 用栈实现队列
//请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作（push、pop、peek、empty）：
//实现 MyQueue 类：
public class Num232 {
    private Stack<Integer> s1=new Stack<>();
    private Stack<Integer> s2=new Stack<>();


    public Num232() {

    }

    public void push(int x) {
        if(s1.isEmpty()){
            s1.push(x);
        }else {
            while (!s1.isEmpty()){
                s2.push(s1.pop());
            }
            s1.push(x);
            while (!s2.isEmpty()){
                s1.push(s2.pop());
            }
        }
    }

    public int pop() {
        return s1.pop();
    }

    public int peek() {
        return s1.peek();
    }

    public boolean empty() {
        return s1.isEmpty();
    }

}
